import { defineEventHandler, getRouterParam, readBody } from 'h3';

// 资源生命周期状态枚举
enum ResourceLifecycleStatus {
  DRAFT = 'DRAFT',
  ACTIVE = 'ACTIVE',
  SUSPENDED = 'SUSPENDED',
  ARCHIVED = 'ARCHIVED',
}

export default defineEventHandler(async (event) => {
  const resourceId = getRouterParam(event, 'resourceId');
  const body = await readBody(event);
  const { status, reason } = body;

  // 验证状态值
  if (!Object.values(ResourceLifecycleStatus).includes(status)) {
    return {
      code: 400,
      msg: '无效的生命周期状态',
    };
  }

  // 模拟状态更新
  const result = {
    resourceId,
    status,
    reason,
    updatedAt: new Date().toISOString(),
    operator: 'admin', // 模拟操作者
  };

  return {
    code: 0,
    data: result,
    msg: '资源生命周期状态更新成功',
  };
});
